<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>采购申请管理</title>
	<meta name="decorator" content="ani"/>
	<style type="text/css">
		._citys { width: 450px; display: inline-block; border: 1px solid #63B8FF; padding: 5px; position: relative;background-color: #C4C4C4; }
		._citys span { color: #424242; height: 15px; width: 15px; line-height: 15px; text-align: center; border-radius: 3px; position: absolute; right: 10px; top: 10px; border: 1px solid #56b4f8; cursor: pointer; }
		._citys0 { width: 100%; height: 34px; display: inline-block; border-bottom: 2px solid #56b4f8; padding: 0; margin: 0; background-color: #C4C4C4;}
		._citys0 li { display: inline-block; line-height: 34px; font-size: 15px; color: #888; width: 80px; text-align: center; cursor: pointer; }
		.citySel { background-color: #56b4f8; color: #424242 !important; }
		._citys1 { width: 100%; display: inline-block; padding: 10px 0; background-color: #C4C4C4;}
		._citys1 a { width: 83px; height: 35px; display: inline-block; background-color:#3B3B3B; color: #EED2EE; margin-left: 6px; margin-top: 3px; line-height: 35px; text-align: center; cursor: pointer; font-size: 13px; overflow: hidden; }
		._citys1 a:hover { color: #3B3B3B; background-color: #E0E0E0; }
		.AreaS { background-color: #FFC0CB  !important; color: #BC8F8F !important; }
	</style>
	<script type="text/javascript">
		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/ap/procurementApplication/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	$table.bootstrapTable('refresh');
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
	        $('#date').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
		});
		
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="procurementApplication" action="${ctx}/ap/procurementApplication/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<table class="table table-bordered">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right">部门：</label></td>
					<td class="width-35">
						<form:input path="bm" htmlEscape="false"  readonly="true"  class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">申请日期：</label></td>
					<td class="width-35">
						<p class="input-group">
							<div class='input-group form_datetime' id='date'>
			                    <input type='text'  name="date" class="form-control "  value="<fmt:formatDate value="${procurementApplication.date}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
			                    <span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
			                </div>						            
			            </p>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">申请人：</label></td>
					<td class="width-35">
						<form:input path="sqr" htmlEscape="false"  readonly="true"  class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">总金额（剔税）：</label></td>
					<td class="width-35">
						<form:input path="zje" htmlEscape="false"  readonly="true"  class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">票据类型（剔税）：</label></td>
					<td class="width-35">
						<form:select path="pj" class="form-control required">
							<form:options items="${fns:getDictList('invoice_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right">总金额（含税）：</label></td>
					<td class="width-35">
						<form:input path="zjehs" htmlEscape="false"  readonly="true"  class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">票据类型（含税）：</label></td>
					<td class="width-35">
						<form:select path="phhs" class="form-control required">
							<form:options items="${fns:getDictList('invoice_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right">采购说明：</label></td>
					<td class="width-35">
						<form:input path="cgsm" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">单据号：</label></td>
					<td class="width-35">
						<form:input path="code" htmlEscape="false"  readonly="true"  class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">供应商及联系方式：</label></td>
					<td class="width-35">
						<form:input path="gys" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">采购实施部门：</label></td>
					<td class="width-35">
						<form:select path="cgbm" class="form-control required">
							<form:options items="${fns:getDictList('depart')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right">验收部门：</label></td>
					<td class="width-35">
						<form:select path="ysbm" class="form-control required">
							<form:options items="${fns:getDictList('depart')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">单据状态：</label></td>
					<td class="width-35">
						<form:input path="status" htmlEscape="false" readonly="true"   class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">费用类型：</label></td>
					<td class="width-35">
						<input type="hidden" name="pro" value="${procurementApplication.pro}"/>
						<form:input path="type" htmlEscape="false" id="city" autocomplete="off"  class="form-control "/>
						<script>
                            $("#city").click(function (e) {
                                var province;
                                var area;
                                $.ajax({
                                    url:'${ctx}/ap/sub/getJson',
                                    async: false,
                                    success:function (data) {
                                        province=data;
                                    }
                                });
                                <%--$.ajax({--%>
                                <%--url:'${ctx}/ap/sub/getJson1',--%>
                                <%--async: false,--%>
                                <%--success:function (data) {--%>
                                <%--area=data;--%>
                                <%--}--%>
                                <%--});--%>
                                SelCity(this,e,province,area);
                            });
						</script>
					</td>
				</tr>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">采购申请明细：</a>
                </li>
            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#applicationDetilList', applicationDetilRowIdx, applicationDetilTpl);applicationDetilRowIdx = applicationDetilRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>

						<th>名称</th>
						<th>品牌型号</th>
						<th>规格/单位</th>
						<th>数量</th>
						<th>单价（剔税）</th>
						<th>总价（剔税）</th>
						<th>单价（含税）</th>
						<th>总价（含税）</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="applicationDetilList">
				</tbody>
			</table>
			<script type="text/template" id="applicationDetilTpl">//<!--
				<tr id="applicationDetilList{{idx}}">
					<td class="hide">
						<input id="applicationDetilList{{idx}}_id" name="applicationDetilList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="applicationDetilList{{idx}}_delFlag" name="applicationDetilList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					

					
					
					<td>
						<input id="applicationDetilList{{idx}}_mc" name="applicationDetilList[{{idx}}].mc" type="text" value="{{row.mc}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_pp" name="applicationDetilList[{{idx}}].pp" type="text" value="{{row.pp}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_gg" name="applicationDetilList[{{idx}}].gg" type="text" value="{{row.gg}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_sl" name="applicationDetilList[{{idx}}].sl" type="text" value="{{row.sl}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_dj" name="applicationDetilList[{{idx}}].dj" type="text" value="{{row.dj}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_zj" name="applicationDetilList[{{idx}}].zj" type="text" value="{{row.zj}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_djhs" name="applicationDetilList[{{idx}}].djhs" type="text" value="{{row.djhs}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_zjhs" name="applicationDetilList[{{idx}}].zjhs" type="text" value="{{row.zjhs}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="applicationDetilList{{idx}}_remarks" name="applicationDetilList[{{idx}}].remarks"  type="text" value="{{row.remarks}}"    class="form-control "/>
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#applicationDetilList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var applicationDetilRowIdx = 0, applicationDetilTpl = $("#applicationDetilTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(procurementApplication.applicationDetilList)};
					for (var i=0; i<data.length; i++){
						addRow('#applicationDetilList', applicationDetilRowIdx, applicationDetilTpl, data[i]);
						applicationDetilRowIdx = applicationDetilRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		</form:form>
</body>
</html>